<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Beats Template</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html">
<img src="../docs-assets/Inform.png" height=72">
</a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../indocn.html">indoc</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=18> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="../../../inweb/index.html">inweb</a></li>
<li><a href="../../../intest/index.html">intest</a></li>

</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Beats Template' generated by Inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">DialogueKit</a></li><li><b>Beats Template</b></li></ul></div>
<p class="purpose">Runtime support for dialogue beats.</p>

<ul class="toc"><li><a href="S-bts.html#SP1">&#167;1. Runtime representation</a></li><li><a href="S-bts.html#SP2">&#167;2. Extracting beat data</a></li><li><a href="S-bts.html#SP3">&#167;3. Accessibility</a></li><li><a href="S-bts.html#SP4">&#167;4. Availability</a></li><li><a href="S-bts.html#SP5">&#167;5. Relevance</a></li><li><a href="S-bts.html#SP6">&#167;6. Performing beats</a></li><li><a href="S-bts.html#SP7">&#167;7. Perform opening beat rule</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Runtime representation. </b>Values representing beats are enumerated from 1 to <span class="extract"><span class="extract-syntax">NO_DIALOGUE_BEATS</span></span>. Beats
have certain properties stored by Inform just as it would for any other
enumerated kind, and which this kit deals with by calls to <span class="extract"><span class="extract-syntax">GProperty</span></span> and
<span class="extract"><span class="extract-syntax">WriteGProperty</span></span>: in particular, <span class="extract"><span class="extract-syntax">performed</span></span> and <span class="extract"><span class="extract-syntax">recurring</span></span>.
</p>

<p class="commentary">In addition, though, the compiler (or more accurately the linker) generates
a table called <span class="extract"><span class="extract-syntax">TableOfDialogueBeats</span></span>. If <span class="extract"><span class="extract-syntax">db</span></span> is an enumerated value then
<span class="extract"><span class="extract-syntax">TableOfDialogueBeats--&gt;db</span></span> is the address of the metadata table for <span class="extract"><span class="extract-syntax">db</span></span>.
(And <span class="extract"><span class="extract-syntax">TableOfDialogueBeats--&gt;0</span></span> is set to <span class="extract"><span class="extract-syntax">NO_DIALOGUE_BEATS</span></span>.)
</p>

<p class="commentary">These beat data arrays are of variable length (at least 4) and have fields as follows:
</p>

<ul class="items"><li>&#9679; <span class="extract"><span class="extract-syntax">AVAILABILITY_DCMETADATA</span></span> is a function to test whether any <span class="extract"><span class="extract-syntax">if</span></span> or <span class="extract"><span class="extract-syntax">unless</span></span>
conditions attached to the choice are met, and whether any constraints on
sequencing of beats ("after", "before", "later", "next", "immediately after")
are met. The function returns <span class="extract"><span class="extract-syntax">true</span></span> if the choice is available, <span class="extract"><span class="extract-syntax">false</span></span> if not.
If the <span class="extract"><span class="extract-syntax">AVAILABILITY_DCMETADATA</span></span> is 0, the choice is always available.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">RELEVANCE_DBMETADATA</span></span> is a function <span class="extract"><span class="extract-syntax">R</span></span> which has two purposes: <span class="extract"><span class="extract-syntax">R(pool, false)</span></span>
tests whether the "about..." descriptions for the beat match any of the subjects
in the null-terminated array <span class="extract"><span class="extract-syntax">pool</span></span>. The function returns <span class="extract"><span class="extract-syntax">true</span></span> if so, <span class="extract"><span class="extract-syntax">false</span></span>
if not. If <span class="extract"><span class="extract-syntax">RELEVANCE_DBMETADATA</span></span> is 0, the beat is never "relevant".
</li></ul>
<p class="commentary"><span class="extract"><span class="extract-syntax">R(pool, true)</span></span> in fact ignores <span class="extract"><span class="extract-syntax">pool</span></span>, and instead makes a series of calls to
<span class="extract"><span class="extract-syntax">DirectorAddLiveSubjectList(A)</span></span>, one for each subject <span class="extract"><span class="extract-syntax">A</span></span> which the beat is about.
Vague descriptions such as "about a woman in the Dining Room" do not result in
a call: only explicit ones such as "about the marble-top table". There is no
meaningful return value. If <span class="extract"><span class="extract-syntax">RELEVANCE_DBMETADATA</span></span> is 0, the beat has no explicit
about values, so the call (which of course cannot be made) would do nothing anyway.
</p>

<ul class="items"><li>&#9679; <span class="extract"><span class="extract-syntax">PROGRAM_DBMETADATA</span></span> points to the D-code program for the beat, which is
too complex to explain here: see <a href="S-prg.html" class="internal">Programs Template</a>.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">TIED_SCENE_DBMETADATA</span></span> is either 0 or a valid scene instance value. (Scenes
are enumerated from 1, so 0 cannot be a scene.) This is the scene to which the
beat is tied, if any, and is caused by naming it "This is the finale scene"
instead of "This is the finale beat" (or not naming it at all).
</li><li>&#9679; <span class="extract"><span class="extract-syntax">REQUIRING_DBMETADATA</span></span> is not a single field. The beat data array is of
variable length, and from this point onwards, it is a null-terminated list of
speakers who must be accessible for the beat to be performed. That list can
of course be empty, in which case there will just be a 0 at this position.
</li></ul>
<p class="commentary">All of this must of course match what is compiled in <a href="../runtime-module/5-dbi.html" class="internal">Dialogue Beat Instances (in runtime)</a>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">AVAILABILITY_DBMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RELEVANCE_DBMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">PROGRAM_DBMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TIED_SCENE_DBMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">FIRST_SPEAKER_DBMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">REQUIRING_DBMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">5</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Extracting beat data. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatGetScene</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">TIED_SCENE_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatGetProgram</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">PROGRAM_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatRequiredList</span><span class="plain-syntax"> </span><span class="identifier-syntax">list</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">list</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">WeakKindOfPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">list</span><span class="plain-syntax">) ~= </span><span class="identifier-syntax">LIST_OF_TY</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">REQUIRING_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">len</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">i</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LIST_OF_TY_SetLength</span><span class="plain-syntax">(</span><span class="identifier-syntax">list</span><span class="plain-syntax">, </span><span class="identifier-syntax">len</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">len</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">REQUIRING_DBMETADATA</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="identifier-syntax">PLAYER_CONVERSATIONALIST</span><span class="plain-syntax">) </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">player</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LIST_OF_TY_PutItem</span><span class="plain-syntax">(</span><span class="identifier-syntax">list</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">list</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatFirstSpeaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">FIRST_SPEAKER_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="identifier-syntax">PLAYER_CONVERSATIONALIST</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">player</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Accessibility. </b>A beat is "accessible" to somebody if it is unperformed, or else recurring,
and if that person can currently hear all the speakers on its requiring list.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatAccessible</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">to_whom</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">DIALOGUE_BEAT_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="identifier-syntax">performed</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">DIALOGUE_BEAT_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="identifier-syntax">recurring</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">REQUIRING_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="identifier-syntax">PLAYER_CONVERSATIONALIST</span><span class="plain-syntax">) </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">player</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TestAudibility</span><span class="plain-syntax">(</span><span class="identifier-syntax">to_whom</span><span class="plain-syntax">, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">i</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Availability. </b>A beat is "available" if its "if" and "unless" conditions, together with any
sequencing conditions about other beats having been performed or not performed
prior to now, are all met.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">latest_performed_beat</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatAvailable</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">AVAILABILITY_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">)(</span><span class="identifier-syntax">latest_performed_beat</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Relevance. </b>A beat is "relevant" if at least one of its "about" subject descriptions
matches something in the current subject list.
</p>

<p class="commentary">A two-word array is used as a sort of temporary live subject list in order
to test relevance to a single subject.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatRelevant</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">DirectorBeatRelevantTo</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="identifier-syntax">DialogueTopicPool</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatRelevantTo</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">pool</span><span class="plain-syntax"> </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">print "Is beat ", db, " relevant to any of ... ";</span>
<span class="plain-syntax">    </span><span class="comment-syntax">for (i=0: pool--&gt;i: i++) print (the) pool--&gt;i, " ";</span>
<span class="plain-syntax">    </span><span class="comment-syntax">print " ...?^";</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">RELEVANCE_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">)(</span><span class="identifier-syntax">pool</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatMakeRelevant</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> </span><span class="identifier-syntax">fn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueBeats</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">beatdata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">RELEVANCE_DBMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">) (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">)(</span><span class="identifier-syntax">DialogueTopicPool</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">DirectorMiniPool</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatAbout</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">subject</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DirectorMiniPool</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">subject</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">DirectorBeatRelevantTo</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="identifier-syntax">DirectorMiniPool</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Performing beats. </b>Note that calls to <span class="extract"><span class="extract-syntax">DirectorPerformBeat</span></span> can be nested, and even with the same beat.
This is why <span class="extract"><span class="extract-syntax">DirectorBeatBeingPerformed</span></span> is careful to avoid the possibility of
a scene being started by its tied beat, then starting the beat in turn, which...
and so on.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorPerformBeat</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">without_detecting</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debug_dialogue</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"-- Performing "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">PrintDialogueBeatName</span><span class="plain-syntax">) </span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">DIALOGUE_BEAT_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="identifier-syntax">performed</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_performed_beat</span><span class="plain-syntax"> = </span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DirectorPush</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">DirectorBeatGetScene</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">)) &amp;&amp; (</span><span class="identifier-syntax">without_detecting</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) </span><span class="identifier-syntax">DetectSceneChange</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DirectorBeatMakeRelevant</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DirectorRun</span><span class="plain-syntax">(0);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">DirectorBeatGetScene</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">)) &amp;&amp; (</span><span class="identifier-syntax">without_detecting</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) </span><span class="identifier-syntax">DetectSceneChange</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debug_dialogue</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"-- Performance of "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">PrintDialogueBeatName</span><span class="plain-syntax">) </span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="string-syntax">" ended^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorBeatBeingPerformed</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">1</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">db</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">NO_DIALOGUE_BEATS</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">x</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">: </span><span class="identifier-syntax">x</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">DirectorStackBeat</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="identifier-syntax">db</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorPerformBeatIfUnperformed</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">DirectorBeatBeingPerformed</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DirectorPerformBeat</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Perform opening beat rule. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">PERFORM_OPENING_BEAT_R</span><span class="plain-syntax"> </span><span class="identifier-syntax">db</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">db</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InitialSituation</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">START_BEAT_INIS</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">db</span><span class="plain-syntax">) </span><span class="identifier-syntax">DirectorPerformBeat</span><span class="plain-syntax">(</span><span class="identifier-syntax">db</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">line_performance_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="S-drc.html">&#10094;</a></li><li class="progresssection"><a href="S-drc.html">drc</a></li><li class="progresscurrent">bts</li><li class="progresssection"><a href="S-lns.html">lns</a></li><li class="progresssection"><a href="S-chc.html">chc</a></li><li class="progresssection"><a href="S-prg.html">prg</a></li><li class="progressnext"><a href="S-lns.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

